package com.dubito.buttonsheet

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog

class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.btn).setOnClickListener {
            // Set up BottomSheetDialog
            val bottomSheetDialog = BottomSheetDialog(this)
            bottomSheetDialog.setContentView(R.layout.cat_bottomsheet_scrollable_content)
//            val recyclerView = bottomSheetDialog.findViewById<RecyclerView>(R.id.recycler_view)
//            recyclerView!!.layoutManager = LinearLayoutManager(this)
//            recyclerView.adapter = RecyclerViewAdapter(getData(), this)
            val bottomSheetInternal: View? = bottomSheetDialog.findViewById(R.id.design_bottom_sheet)
            BottomSheetBehavior.from(bottomSheetInternal as View).peekHeight = getPeekHeight()
            bottomSheetDialog.show()
        }
    }


    private fun getData(): ArrayList<String> {
        val lists = arrayListOf<String>()
        for (i in 0..100) {
            lists.add("$i")
        }
        return lists
    }

    private fun getPeekHeight(): Int {
        val heightPixels = resources.displayMetrics.heightPixels
        return heightPixels
    }
}
